package restful;

import org.eclipse.jetty.server.Server;
import org.eclipse.jetty.servlet.ServletContextHandler;
import org.eclipse.jetty.servlet.ServletHolder;

import com.sun.jersey.spi.container.servlet.ServletContainer;

public class JettyRestEndPoint {
	public static void main(String[] args) throws Exception {
		ServletHolder sh = new ServletHolder(ServletContainer.class);

		sh.setInitParameter(
				"com.sun.jersey.config.property.resourceConfigClass",
				"com.sun.jersey.api.core.PackagesResourceConfig");
		sh.setInitParameter("com.sun.jersey.config.property.packages",
				"restful.service");
		String port = "9998";
		if(System.getenv().containsKey("READINGS_PORT")){
			port = System.getenv().get("READINGS_PORT");
		}

		Server server = new Server(Integer.parseInt(port));

		ServletContextHandler context = new ServletContextHandler();
		context.setContextPath("/");
		context.setResourceBase(".");
		context.setClassLoader(Thread.currentThread().getContextClassLoader());
		context.addServlet(sh, "/*");
		server.setHandler(context);

		server.start();
		server.join();

	}
}


